import XlsxDataManager from "./cfw/xlsx/XlsxDataManager";
import LangManager from "./cfw/lang/LangManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Helloworld extends cc.Component {


    @property(cc.JsonAsset)
    gameData: cc.JsonAsset = null;

    onLoad() {
        XlsxDataManager.instance().addFile(this.gameData)
        this.changeLang('zh')
    }


    changeLang(name: string) {
        let lang = name
        let langFileName = 'game_lang_' + lang;
        cc.resources.load('data/' + langFileName, cc.JsonAsset, (err, item: cc.JsonAsset) => {
            if (err || !cc.isValid(this.node)) {
                return;
            }
            cc.log(' langFileName ', langFileName)
            // 2 添加数据到管理器
            XlsxDataManager.instance().addFile(item, langFileName)
            // 3 将语言数据添加到语言管理器
            LangManager.instance().setLang(lang, XlsxDataManager.instance().get(langFileName))
        })
    }

    onButtonChange() {
        let name = LangManager.instance().getLang()
        if (name == 'zh') {
            name = 'en'
        } else {
            name = 'zh'
        }
        this.changeLang(name)
    }

}
